package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbOrderItemMapper;
import com.bw1806.pojo.TbOrderItem;
import com.bw1806.pojo.TbOrderItemExample;
import com.bw1806.sellergoods.service.TbOrderItemService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbOrderItemServiceImpl implements TbOrderItemService {

    @Autowired
    private TbOrderItemMapper tbOrderItemMapper;

    @Override
    public List<TbOrderItem> findAll() {
        return tbOrderItemMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbOrderItem> pagelist(TbOrderItem tbOrderItem,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbOrderItemExample example=new TbOrderItemExample();

        TbOrderItemExample.Criteria criteria = example.createCriteria();

        if(tbOrderItem!=null){
            //if(tbOrderItem.getName()!=null && tbOrderItem.getName().length()>0){
            //    criteria.andNameLike("%"+tbOrderItem.getName()+"%");
           // }
        }

        Page<TbOrderItem> page= (Page<TbOrderItem>) tbOrderItemMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbOrderItem tbOrderItem) {
        Long id = tbOrderItem.getId();
        if(id != null && id !=0){
            tbOrderItemMapper.updateByPrimaryKey(tbOrderItem);
        } else{
            tbOrderItemMapper.insert(tbOrderItem);
        }
    }

    @Override
    public TbOrderItem getById(Long id) {
        return tbOrderItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbOrderItemMapper.deleteByPrimaryKey(id);
        }
        //tbOrderItemMapper.deletebth(ids);
    }
}
